package com.whksoft.mymapplugin.Renderer;

import org.bukkit.entity.Player;
import org.bukkit.map.MapCanvas;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;
import org.bukkit.plugin.IllegalPluginAccessException;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;

import java.awt.image.BufferedImage;

/**
 * 图片渲染器
 */
public class ImageRenderer extends MapRenderer {

    BufferedImage image;
    Plugin plugin;

    public ImageRenderer(BufferedImage image, Plugin plugin) {
        this.image = image;
        this.plugin = plugin;
    }

    @Override
    public void render(MapView map, MapCanvas canvas, Player player) {
        try {
            new BukkitRunnable() {
                public void run() {
                    if (player == null) this.cancel();
                    {//player.sendMessage("别骂了别骂了，在渲染了！");
                        map.setScale(MapView.Scale.FARTHEST);
                        canvas.drawImage(0, 0, image);
                    }
                }
            }.runTaskTimerAsynchronously(plugin, 1, 300);
        } catch (IllegalPluginAccessException ignored){
        }
    }
}
